import 'package:tender_flutter/page/home/model/city_entity.dart';

cityEntityFromJson(CityEntity data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['code'] != null) {
		data.code = json['code'].toString();
	}
	if (json['lat'] != null) {
		data.lat = json['lat'] is String
				? double.tryParse(json['lat'])
				: json['lat'].toDouble();
	}
	if (json['lnt'] != null) {
		data.lnt = json['lnt'] is String
				? double.tryParse(json['lnt'])
				: json['lnt'].toDouble();
	}
	if (json['title'] != null) {
		data.title = json['title'].toString();
	}
	if (json['status'] != null) {
		data.status = json['status'] is String
				? int.tryParse(json['status'])
				: json['status'].toInt();
	}
	if (json['priority'] != null) {
		data.priority = json['priority'].toString();
	}
	if (json['level'] != null) {
		data.level = json['level'] is String
				? int.tryParse(json['level'])
				: json['level'].toInt();
	}
	if (json['region'] != null) {
		data.region = json['region'].toString();
	}
	if (json['areas'] != null) {
		data.areas = new List<CityEntity>();
		(json['areas'] as List).forEach((v) {
			data.areas.add(new CityEntity().fromJson(v));
		});
	}
	return data;
}

Map<String, dynamic> cityEntityToJson(CityEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['code'] = entity.code;
	data['lat'] = entity.lat;
	data['lnt'] = entity.lnt;
	data['title'] = entity.title;
	data['status'] = entity.status;
	data['priority'] = entity.priority;
	data['level'] = entity.level;
	data['region'] = entity.region;
	if (entity.areas != null) {
		data['areas'] =  entity.areas.map((v) => v.toJson()).toList();
	}
	return data;
}